<template>
  <el-card class="box-card">
    <div style="display: flex">
      <span style="color: #000000; font-weight: 600; font-size: 15px; margin-right: 30px">套打模板</span>

      <div>模板设置太麻烦，上<el-button type="primary" size="mini" style="margin: 0 3px" @click="toTemplateLibrary">模板库</el-button>看看</div>
      <el-button type="primary" size="mini" style="margin-left: 50px" @click="toTemplateSetting()">新增模板</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%; margin: 20px 0">
      <el-table-column type="index" label="序号" > </el-table-column>
      <el-table-column prop="orderType" label="单据类型" > </el-table-column>
      <el-table-column prop="name" label="模板名称"> </el-table-column>
      <el-table-column prop="templateNumber" label="模板编号"> </el-table-column>
      <el-table-column prop="templateSize" label="纸张尺寸"> </el-table-column>
      <el-table-column prop="createTime" label="创建日期"> </el-table-column>
      <el-table-column
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleEdit(scope.row)" type="text" size="small">设置</el-button>
      </template>
    </el-table-column>
    </el-table>
    <div style="width: 100%; text-align: right">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="jumper, prev, pager,next, sizes"
        :total="total"
      ></el-pagination>
    </div>
  </el-card>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import { handleOtherPerms } from '@/utils/index'
import Vue from 'vue'
export default {
  name: 'templateSet',
  components: {},
  data() {
    return {
      columnData: [
        {
          title: '单据类型',
          props: 'num',
        },
        {
          title: '模板名称',
          props: 'num',
        },
        {
          title: '模板编号',
          props: 'num',
        },
        {
          title: '纸张尺寸',
          props: 'num',
        },
        {
          title: '创建日期',
          props: 'num',
        },
        {
          title: '操作',
          props: 'num',
        },
      ],
      pageSize: 10, //每页的数据条数
      currentPage: 1, //默认开始页面
      tableData: [],
      total: 0
    }
  },
  created() {
    this.getTableData()
  },
  mounted() {},
  methods: {

    toTemplateLibrary() {
      let printPermissions = handleOtherPerms('打印模板设置')
      if (!printPermissions) {
        return this.$elMessage.warning('没有权限！')
      }
      this.$router.push('/baseInfomation/printSetting/library')
    },
    toTemplateSetting() {
      let printPermissions = handleOtherPerms('打印模板设置')
      if (!printPermissions) {
        return this.$elMessage.warning('没有权限！')
      }
      this.$router.push('/baseInfomation/printSetting/printSet')
    },
    // 获取每页几条数据
    handleSizeChange(val) {
      this.pageSize = val
      this.getTableData()
    },
    // 获取当前第几页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getTableData(val)
    },
    getTableData(val = 1) {
      let params = {
        pageSize: this.pageSize,
        pageNo: val,
        version: Vue.ls.get('accountVersion')
      }
      getAction('/xghprinttemplate/xghPrintTemplate/page', params).then((res) => {
        if (res.success) {
          if (val == 1) {
            this.currentPage = 1
          }
          console.log(res)
          this.tableData = res.result.records
          this.total = res.result.total
        } else {
          this.$elMessage.error(res.message)
        }
      })
    },
    handleEdit(record) {
      let printPermissions = handleOtherPerms('打印模板设置')
      if (!printPermissions) {
        return this.$elMessage.warning('没有权限！')
      }
      console.log(record);
      let billType1 = ['销售出库单','销售退货单','销售换货单','销售订单','采购入库单','采购退货单','采购换货单','采购订单']
      let billType2 = ['收款结算单','付款结算单','一般费用单','其他收入单','转账单','物流代收结算单','物流代付结算单','物流运费结算单']
      let billType3 = ['盘点单','调拨单同价调拨','调拨单变价调拨','报损单','报溢单','成本调整单','其他入库单','其他出库单','期初库存录入','库存调整单','资金增加','资金减少','应收款增加','应收款减少','应付款增加','应付款减少']
      let orderName = record.orderType
      let name = ''
      if (billType1.includes(orderName)) name = 'baseInfomation-printSetting-printSet'
      if (billType2.includes(orderName)) name = 'baseInfomation-printSetting-printSetSettlement'
      if (billType3.includes(orderName)) name = 'baseInfomation-printSetting-printSetStock'
      this.$router.push({
          name,
          params: {
            val: record.orderType,
            type: 'edit',
            tlId: record.id,
          },
        })
    }
  },
}
</script>

<style lang="scss" scoped>
.el-button--mini {
  border-radius: 6px;
}
</style>

